import Vue from 'vue'
import Router from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'
// import About from "@/components/About"
// import Home from "@/components/Home"
// import User from "@/components/User"

// 路由懒加载写法,区别主要是build之后js文件结构
// const Home = () => import("@/components/Home");
// const About = () => import("@/components/About");
// const User = () => import("@/components/User");
// const HomeNews = () => import("@/components/HomeNews");
// const Profile = () => import("@/components/Profile");
// const TabBar = () => import("@/components/tabbar/TabBar");

const Home = () => import("@/views/home/Home.vue");
const Category = () => import("@/views/category/Category.vue");
const Profile = () => import("@/views/profile/Profile.vue");
const Shopcart = () => import("@/views/shopcart/Shopcart.vue");

Vue.use(Router)

const router = new Router({
  routes: [
    // {
      // 路径缺省时,路由到home
      // path: '/',

    //   redirect: "/home"
    // },
    // {
    //   path: "/about",
    //   name: "About",
    //   component: About
    // },
    // {
    //   path: "/home",
    //   name: "Home",
    //   component: Home,
    //   children:[
    //     {
    //       path: "news",
    //       component: HomeNews
    //     }
    //   ]
    // },
    // {
    //   path: "/user/:userId",
    //   name: "User",
    //   component: User
    // },
    // {
    //   path: "/Profile",
    //   name: "Profile",
    //   component: Profile
    // },
    // {
    //   path: "/tabBar",
    //   name: "TabBar",
    //   component: TabBar
    // }
    {
      path: "/home",
      name: "Home",
      component: Home
    },
    {
      path: "/category",
      name: "Category",
      component: Category
    },
    {
      path: "/shopcart",
      name: "Shopcart",
      component: Shopcart
    },
    {
      path: "/profile",
      name: "Profile",
      component: Profile
    }
  ],
  // 默认配置为hash,浏览器路径上会带有#号,使用history就没有了
  mode: "history"
})

// 全局路由前置守卫
router.beforeEach((to, from, next) => {
  console.log("全局前置路由守卫");
  next();
})

// 全局路由后置守卫
router.afterEach((to, from, next) => {
  console.log("全局后置路由守卫");
})

const originalPush = Router.prototype.push
   Router.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

export default router;